<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/easyui/validatebox-extend.js"></script>
<script type="text/javascript" src="/easyui/datagrid-detailview.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Measure，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="measure_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/measure-list/1/20',
					  method:'get',
					  toolbar:'#tb',
					  <#--fitColumns : true,-->
					  <#--rowStyler: function(index,row){-->
                        <#--if (row.closeSymbol=='0'){-->
                            <#--return 'background-color:#FF9797;color:#fff;font-weight:bold;';-->
                        <#--}-->
				      <#--},-->
					  onLoadSuccess:function(data){
                        $('.edit').linkbutton({plain:true,iconCls:'icon-edit'});
                        $('.delete').linkbutton({plain:true,iconCls:'icon-remove'});
                        $('.add').linkbutton({plain:true,iconCls:'icon-write-card'});
                        $('.print').linkbutton({plain:true,iconCls:'icon-print'});
                    },
					  loadMsg : '数据加载中',				 
					  showFooter: true" >
        <thead>
             <th data-options="field:'id',width:200,align:'center' ,formatter:idFormatter">操作</th>
             <th data-options="field:'closeSymbol',width:150,align:'center',formatter:closeSymbolFormatter">计量关闭</th>
             <th data-options="field:'measureId',width:210,align:'center'">磅单号</th>
             <th data-options="field:'carId',width:210,align:'center'">车牌号</th>

             <th data-options="field:'moveType',width:100,align:'center' ,formatter:moveTypeFormatter">进/出厂</th>
             <th data-options="field:'grossWeight',width:100,align:'center',formatter:grossWeightFormatter">毛重</th>
             <th data-options="field:'tare',width:100,align:'center',formatter:tareFormatter">皮重</th>
             <th data-options="field:'suttle',width:100,align:'center',formatter:suttleFormatter">净重</th>
             <th data-options="field:'materialName',width:200,align:'center'">物料名称</th>
             <th data-options="field:'supplierName',width:200,align:'center'">供应商</th>
             <th data-options="field:'customerName',width:200,align:'center'">采购商</th>
             <th data-options="field:'suttleDate',width:200,align:'center'">净重产生时间</th>
             <th data-options="field:'isPublish',width:200,align:'center'">修改人员</th>
             <th data-options="field:'updateTime',width:200,align:'center'">修改时间</th>
        </thead>
	</table>
</div>


<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">

    <div style="margin:5px 0;"></div>
    <div>
        净重开始时间：<input class="easyui-datetimebox" hidden data-options="formatter:dateformatter,parser:dateparser" id="suttleDateSearch" style="width:180px">
        净重结束时间：<input class="easyui-datetimebox" hidden data-options="formatter:dateformatter,parser:dateparser" id="suttleDateToSearch" style="width:180px">
        物料:<input class="easyui-textbox" id="materialNameSearch" style="width:120px" >
        供应商:<input class="easyui-textbox" id="supplierNameSearch" style="width:120px" >
        采购商:<input class="easyui-textbox" id="customerNameSearch" style="width:120px" >
    </div>

	<div>
        退货标志:
        <input class="easyui-combobox" name="return"id="return"
               data-options="
				url : '/constants/return-symbol-types',
				method: 'get',
				valueField:'key',
				textField:'value',
				">
        计量状态:
        <input class="easyui-combobox" name="close"id="close"
               data-options="
				url : '/constants/close-symbol-types',
				method: 'get',
				valueField:'key',
				textField:'value',
				">
        磅单号:<input class="easyui-textbox" id="measureId" style="width:120px" >
        进出厂方式:
        <input class="easyui-combobox" name="outin"id="outin"
               data-options="
				url : '/constants/move-types',
				method: 'get',
				valueField:'key',
				textField:'value',
				">
        车牌号: <input class="easyui-textbox" id="carId" name="carId" style="width:120px" >
	</div>
    <div style="margin:5px 0;"></div>
    <div>
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin:5px 0;"></div>
    <#include "/common/button.html">
</div>

<div id="dlg" class="easyui-dialog" style="width:800px;" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fm" method="post" novalidate style="padding:10px 2px 2px 2px">
        <table class="dv-table" style="width:100%;background:#fafafa;margin-right: 5px;border: black">
			<tr>
				<td style="width: 20%" align="center">
                    计量单号
				</td>
				<td style="width: 20%" align="center">
                    <input name="measureId" id="measureId" readonly class="easyui-textbox"  missingMessage="请输入计量单号" style="width:100%">
				</td>
                <td style="width: 20%" align="center">
                    <font color="red">车牌号</font>
				</td>
                <td style="width: 20%" align="center">
                    <input name="carId" id="carId" require="true" class="easyui-textbox"  missingMessage="请输入车牌号" style="width:100%">
                </td>
			</tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">物料名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="materialName" id="materialName"  class="easyui-textbox"  missingMessage="请输入物料名称" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">供应商名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="supplierName" id="supplierName"  class="easyui-textbox"  missingMessage="请输入供应商名称" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">客户商名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="customerName" id="customerName"  class="easyui-textbox"  missingMessage="请输入客户商名称" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">移动类型</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="moveType" id="moveType"  class="easyui-textbox"  missingMessage="移动类型" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">库房名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="storageName" id="storageName"  class="easyui-textbox"  missingMessage="请输入库房名称" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    毛重
                </td>
                <td style="width: 29%" align="center">
                    <input name="grossWeight" id="grossWeight" readonly class="easyui-textbox"  missingMessage="请输入毛重" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">毛重计量点</font>
				</td>
                <td style="width: 29%" align="center">
                    <input name="grossWeightSite" id="grossWeightSite"  class="easyui-textbox"  missingMessage="请输入毛重计量点" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">毛重计量员</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="grossWeightP" id="grossWeightP"  class="easyui-textbox"  missingMessage="请输入毛重计量员" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    毛重时间
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="grossWeightDate" id="grossWeightDate" missingMessage="请选择毛重时间" readonly style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    皮重
                </td>
                <td style="width: 29%" align="center">
                    <input name="tare" id="tare" readonly class="easyui-textbox"  missingMessage="请输入皮重" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">皮重计量点</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="tareSite" id="tareSite"  class="easyui-textbox"  missingMessage="请输入皮重计量点" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">皮重计量员</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="tareP" id="tareP"  class="easyui-textbox"  missingMessage="请输入皮重计量员" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    皮重时间
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="tareDate" id="tareDate" missingMessage="请输入皮重时间" readonly style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    净重
                </td>
                <td style="width: 29%" align="center">
                    <input name="suttle" id="suttle" readonly class="easyui-textbox"  missingMessage="请输入净重" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    产生净重时间
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="suttleDate" id="suttleDate" missingMessage="请输入产生净重时间" readonly  style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">卸货标志</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="unloadSymbol" id="unloadSymbol" require="true" data-options="
						url : '/constants/unload-symbol-types',
						method: 'get',
						valueField:'key',
						textField:'value',
				"  class="easyui-combobox"  missingMessage="请输入卸货标志" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    卸货时间
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="unloadDate" id="unloadDate" missingMessage="请输入卸货时间" readonly style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    库工员
                </td>
                <td style="width: 29%" align="center">
                    <input name="storagep" id="storagep" readonly class="easyui-textbox"  missingMessage="请输入库工员" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">退货标志</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="returnSymbol" id="returnSymbol" require="true" data-options="
						url : '/constants/return-symbol-types',
						method: 'get',
						valueField:'key',
						textField:'value',
				" class="easyui-combobox"  missingMessage="请输入退货标志" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">退货原因</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="returnYY" id="returnYY"  class="easyui-textbox"  missingMessage="请输入退货原因" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">计量关闭标志</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="closeSymbol" id="closeSymbol" require="true" data-options="
						url : '/constants/close-symbol-types',
						method: 'get',
						valueField:'key',
						textField:'value',
				" class="easyui-combobox"  missingMessage="请输入计量关闭标志" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">车辆最大载重量</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="max" id="max" class="easyui-textbox"  missingMessage="请输入最大载重量" style="width:100%">
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="save()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>

<!-- wangyoupeng -->

<div id="dlgWYP" class="easyui-dialog" style="width:800px;" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fmWYP" method="post" novalidate style="padding:10px 2px 2px 2px">
        <table class="dv-table" style="width:100%;background:#fafafa;margin-right: 5px;border: black">
            <tr>
                <td style="width: 20%" align="center">
                    计量单号
                </td>
                <td style="width: 20%" align="center">
                    <input name="measureId" id="measureId1" readonly class="easyui-textbox"  missingMessage="请输入计量单号" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">车牌号</font>
                </td>
                <td style="width: 20%" align="center">
                    <input name="carId" id="carId1" require="true" class="easyui-textbox"  missingMessage="请输入车牌号" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">物料名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="materialName" id="materialName1"  class="easyui-textbox"  missingMessage="请输入物料名称" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">供应商名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="supplierName" id="supplierName1"  class="easyui-textbox"  missingMessage="请输入供应商名称" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">客户商名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="customerName" id="customerName1"  class="easyui-textbox"  missingMessage="请输入客户商名称" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">移动类型</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="moveType" id="moveType1"  class="easyui-textbox"  missingMessage="请输入客户商名称" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">库房名称</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="storageName" id="storageName1"  class="easyui-textbox"  missingMessage="请输入库房名称" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">毛重</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="grossWeight" id="grossWeight1"  class="easyui-textbox"  missingMessage="请输入毛重" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">毛重计量点</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="grossWeightSite" id="grossWeightSite1"  class="easyui-textbox"  missingMessage="请输入毛重计量点" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">毛重计量员</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="grossWeightP" id="grossWeightP1"  class="easyui-textbox"  missingMessage="请输入毛重计量员" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">毛重时间</font>
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="grossWeightDate" id="grossWeightDate1" missingMessage="请选择毛重时间"  style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">皮重</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="tare" id="tare1"  class="easyui-textbox"  missingMessage="请输入皮重" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">皮重计量点</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="tareSite" id="tareSite1"  class="easyui-textbox"  missingMessage="请输入皮重计量点" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">皮重计量员</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="tareP" id="tareP1"  class="easyui-textbox"  missingMessage="请输入皮重计量员" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">皮重时间</font>
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="tareDate" id="tareDate1" missingMessage="请输入皮重时间"  style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    净重
                </td>
                <td style="width: 29%" align="center">
                    <input name="suttle" id="suttle1"  class="easyui-textbox" readonly  missingMessage="请输入净重" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">产生净重时间</font>
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="suttleDate" id="suttleDate1" missingMessage="请输入产生净重时间"   style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">卸货标志</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="unloadSymbol" id="unloadSymbol1" require="true" data-options="
						url : '/constants/unload-symbol-types',
						method: 'get',
						valueField:'key',
						textField:'value',
				"  class="easyui-combobox"  missingMessage="请输入卸货标志" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">卸货时间</font>
                </td>
                <td style="width: 29%" align="center">
                    <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" name="unloadDate" id="unloadDate1" missingMessage="请输入卸货时间"  style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">库工员</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="storagep" id="storagep1"  class="easyui-textbox"  missingMessage="请输入库工员" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">退货标志</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="returnSymbol" id="returnSymbol1" require="true" data-options="
						url : '/constants/return-symbol-types',
						method: 'get',
						valueField:'key',
						textField:'value',
				" class="easyui-combobox"  missingMessage="请输入退货标志" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">退货原因</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="returnYY" id="returnYY1"  class="easyui-textbox"  missingMessage="请输入退货原因" style="width:100%">
                </td>
            </tr>
            <tr>
                <td style="width: 20%" align="center">
                    <font color="red">计量关闭标志</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="closeSymbol" id="closeSymbol1" require="true" data-options="
						url : '/constants/close-symbol-types',
						method: 'get',
						valueField:'key',
						textField:'value',
				" class="easyui-combobox"  missingMessage="请输入计量关闭标志" style="width:100%">
                </td>
                <td style="width: 20%" align="center">
                    <font color="red">车辆最大载重量</font>
                </td>
                <td style="width: 29%" align="center">
                    <input name="max" id="max1" class="easyui-textbox"  missingMessage="请输入最大载重量" style="width:100%">
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveWYP()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgWYP').dialog('close')" style="width:90px">取消</a>
</div>


<script type="text/javascript">
    $('#searchByParameter').click(function () {
        var measureId = $("#measureId").val();
        var moveTypes = $("#outin").val();
        var carId = $("#carId").val();
        var returnSymbol = $("#return").val();
        var closeSymbol = $("#close").val();

        //毛重
        var grossFrom = '';
        var grossTo = '';
        var tareFrom = '';
        var tareTo = '';
        var suttleDate = $('#suttleDateSearch').val();
        var suttleDateTo = $('#suttleDateToSearch').val();

        var materialName = $('#materialNameSearch').val();
        var supplierName = $('#supplierNameSearch').val();
        var customerName = $('#customerNameSearch').val();

        var handler = '/measure-list/1/20?measureId='+measureId+'&moveTypes='+moveTypes+
                '&carId='+carId+'&returnSymbol='+returnSymbol+'&closeSymbol='+closeSymbol+
                '&materialName='+materialName+'&supplierName='+supplierName+'&customerName='+customerName+
                '&suttleDate='+suttleDate+'&suttleDateTo='+suttleDateTo+
                '&grossFrom='+grossFrom+"&grossTo="+grossTo+"&tareFrom="+tareFrom+"&tareTo="+tareTo;
        $('#measure_table').datagrid('options').url = handler;
        $('#measure_table').datagrid('reload');
    })
</script>

<script type="text/javascript">
    function dateformatterSuttle(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }
    function dateparserSuttle(s){
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }

</script>


<script type="text/javascript">
    function dateformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        var hor = date.getHours();
        var min = date.getMinutes();
        var sec = date.getSeconds();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+' '+(hor<10?('0'+hor):hor)+':'+(min<10?('0'+min):min)+':'+(sec<10?('0'+sec):sec);
    }
    function moveTypeFormatter(value,index){
        var result ='';
        $.ajax({
            url : '/constants/move-types/'+value,
            async :false,
            success :function (data) {
                result = data
            }
        })
        if(result=='采购进厂'){
            return '<span style="background-color: #6384cc"><font color="black">'+result+'</font></span>';
        }else if(result=='销售出厂'){
            return '<span style="background-color: #ffff33"><font color="black  ">'+result+'</font></span>';
        }
    };
    function returnSymbolFormatter(value,index) {
        var result ='';
        $.ajax({
            url : '/constants/return-symbol-types/'+value,
            async :false,
            success :function (data) {
                result = data
            }
        })
        return result;
    };
    function grossWeightFormatter(value,index) {
        return value+'(吨)'
    };
    function tareFormatter(value,index) {
        return value+'(吨)'
    };

    function suttleFormatter(value,index) {
        return value+'(吨)'
    }
    function unloadSymbolFormatter(value,index) {
        var result ='';
        $.ajax({
            url : '/constants/unload-symbol-types/'+value,
            async :false,
            success :function (data) {
                result = data
            }
        })
        return result;
    };
    function closeSymbolFormatter(value,index) {
        var result ='';
        $.ajax({
            url : '/constants/close-symbol-types/'+value,
            async :false,
            success :function (data) {
                result = data
            }
        })
        return result;
    }
    function dateparser(s){
        if (!s) return new Date();

        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        var hour,min,sec;
        try {
            var hfm = (s.split(' '))[1];
            hour = parseInt(hfm.split(':')[0]);
            min = parseInt(hfm.split(':')[1]);
            sec = parseInt(hfm.split(':')[2]);
        }
        catch(err){
            hour = '00';
            min  = '00';
            sec = '00'

        }
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)&&!isNaN(hour) && !isNaN(min) && !isNaN(sec)){
            return new Date(y,m-1,d,hour,min,sec);
        } else {
            return new Date();
        }
    }
    function closeSymbolFormatter(value,row) {
        if(value=="1"){
            return "计量完闭"
        }else if(value=="0"){
            return '<span style="background-color: #FF9797;font-weight:bold;"><font color="black">'+'未计量完'+'</font></span>';
        }
    }
    function idFormatter(value,row){
        var button ='';
        var rjson = JSON.stringify(row)
        button += '<div style="background-color:#cccccc"> ';
        // button += '<a href="#" class="delete" title="删除" onclick=\'del('+value+')\'></a>';
        button += '<a href="#" class="edit" title="编辑" onclick=\'edit('+value+','+rjson+')\'></a> '
        button += '<a href="#" class="add" title="写卡" onclick=\'add('+value+','+rjson+')\'></a>';
        if(row.closeSymbol==1){

            button += '<a href="#" class="print" title="打印" onclick=\'print('+value+','+rjson+')\'></a></div>';
        }
        return button;
    }

    $('#measure_table').datagrid({
        view: detailview,
        detailFormatter: function(rowIndex, rowData){
            var us = '未确认'
            if(rowData.unloadSymbol=='1'){
                us = '已确认'
            }
            var rs = '未退货'
            if(rowData.returnSymbol=='1'){
                rs = '已退货'
            }
            return '<table style="border: 5px"><tr>' +
                    '<td style="border:1px">' +
                    '<p><span style="font-weight:bold">毛重时间</span>: ' + rowData.grossWeightDate + '</p>' +
                    '<p><span style="font-weight:bold">毛重计量员</span>: ' + rowData.grossWeightP + '</p>' +
                    '<p><span style="font-weight:bold">毛重计量点</span>: ' + rowData.grossWeightSite + '</p>' +
                    '<p><span style="font-weight:bold">皮重时间</span>: ' + rowData.tareDate + '</p>' +
                    '<p><span style="font-weight:bold">皮重计量员</span>: ' + rowData.tareP + '</p>' +
                    '<p><span style="font-weight:bold">皮重计量点</span>: ' + rowData.tareSite + '</p>' +
                    '</td>' +
                    '<td style="border:1px">' +
                    '</td>' +
                    '<td style="border: 1px">'+
                    '<p><span style="font-weight:bold">车号</span>: ' + rowData.carId + '</p>' +
                    '<p><span style="font-weight:bold">库房名称</span>: ' + rowData.storageName + '</p>' +
                    '<p><span style="font-weight:bold">物料名称</span>: ' + rowData.materialName + '</p>' +
                    '<p><span style="font-weight:bold">卸货标记</span>: ' + us + '</p>' +
                    '<p><span style="font-weight:bold">退货标记</span>: ' + rs + '</p>' +
                    '<p><span style="font-weight:bold">退卸备注</span>: ' + rowData.remarks1 + '</p>' +

                    '</td>'+
                    '</tr></table>';
        }
    });
</script>

<!-- 按钮操作 -->
<script type="text/javascript">

    //新增按钮
    $('#add').click(function () {
        var url = '/business-measure-add';
        var index = layer.open({
            title:'计量单新增',
            type: 2,
            area: ['900px', '700px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });

    //删除按钮
    $('#delete').click(function () {
        var row = $('#measure_table').datagrid('getSelected');
        if(!row){
            layer.msg('请选择需要删除的计量单', {icon: 2});
        }else{
            layer.confirm('确定删除计量单？', {
                btn: ['删除','取消'] //按钮
            }, function(){
                $.ajax({
                    url : '/measure-ins-upd-del/'+row.id,
                    data : {deleteFlag:'Y',tm : new Date().getTime()},
                    async : false,
                    success : function(){
                        $('#measure_table').datagrid('reload');
                    }
                });
                layer.closeAll('dialog');
            }, function(){

            });

        }
    });
    //修改按钮
    $("#edit").click(function () {
        var row = $('#measure_table').datagrid('getSelected');
        if (row){
            $('#dlgWYP').dialog('open').dialog('center').dialog('setTitle','编辑');
            $('#fmWYP').form('load',row);
            url = '/measure-ins-upd-del/'+row.id;
        } else {
            layer.msg("请选择需要编辑的常量",{icon: 2})
        }
    });

	var url;
	//编辑
    function edit(value,row){
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑');
        $('#fm').form('load',row);
        url = '/measure-ins-upd-del/'+value;
    }
    //写卡
    function add(value,row) {
        url = '/measure-write/'+row.measureId;
        $.ajax({
            url: url,
            async :true,
            success : function (data) {
                layer.msg("写卡成功",{icon: 1})
            }
        })
    }
    //打印
    function print(value,row){
        url = '/measure-print/' + row.measureId;
        $.ajax({
            url: url,
            async :true,
            beforeSend: function(){
                layer.msg("打印中");
            },
            success : function (data) {
                layer.msg("打印成功",{icon: 1})
            }
        })
    }



    //计量人员修改保存
	function save(){
        var max = $('#max').val();
        var regFH = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/;
        var reg = new RegExp("^[0-9]+(.[0-9]{1,3})?$");
        if(regFH.test(max)){
            layer.msg("不能出现中文符号！")
            return false;
        }
        if(!reg.test(max)){
            layer.msg("请确认最大载重量是否输入正确！")
            return false;
        }
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
				$('#dlg').dialog('close');        // close the dialog
				$('#measure_table').datagrid('reload');    // reload the user data
            }
        });
    }

    //管理员权限修改
    function saveWYP(){
        var grossWeight = $('#grossWeight1').val();
        var tare = $('#tare1').val();
        var max = $('#max1').val();
        var regFH = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/;
        var reg = new RegExp("^[0-9]+(.[0-9]{1,3})?$");
        if(regFH.test(grossWeight)){
            layer.msg("不能出现中文符号！")
            return false;
        }
        if(!reg.test(grossWeight)){
            layer.msg("请确认毛重是否输入正确！")
            return false;
        }
        if(regFH.test(tare)){
            layer.msg("不能出现中文符号！")
            return false;
        }
        if(!reg.test(tare)){
            layer.msg("请确认皮重是否输入正确！")
            return false;
        }
        if(regFH.test(max)){
            layer.msg("不能出现中文符号！")
            return false;
        }
        if(!reg.test(max)){
            layer.msg("请确认最大载重量是否输入正确！")
            return false;
        }
        $('#fmWYP').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                $('#dlgWYP').dialog('close');        // close the dialog
                $('#measure_table').datagrid('reload');    // reload the user data
            }
        });
    }

    function del(value) {
        url = '/measure-ins-upd-del/'+value;
        $.messager.confirm('删除信息','确定删除此项目?',function(r){
            if (r){
                $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                    $('#measure_table').datagrid('reload');    // reload the user data
                });
            }
        });
    }
    $('#export').click(function(){

        var measureId = $("#measureId").val();
        var moveTypes = $("#outin").val();
        var unload = $("#unload").val();
        var returnSymbol = $("#return").val();
        var closeSymbol = $("#close").val();
        var carId = $("#carId").val();

        var materialName = $('#materialNameSearch').val();
        var supplierName = $('#supplierNameSearch').val();
        var customerName = $('#customerNameSearch').val();

        var suttleDate = $('#suttleDateSearch').val();
        var suttleDateTo = $('#suttleDateToSearch').val();

        //  = '/?measureId='+measureId
        //         +'&materialName='+materialName+'&supplierName='+supplierName+'&customerName='+customerName
        //         +'&suttleDate='+suttleDate
        //         +'&moveTypes='+moveTypes+'&unloadSymbol='+unload+'&returnSymbol='+returnSymbol+'&closeSymbol='+closeSymbol+'&carId='+carId;
        window.location = '/measure-download?measureId='+measureId+'&moveTypes='+moveTypes+
                '&carId='+carId+'&returnSymbol='+returnSymbol+'&closeSymbol='+closeSymbol+
                '&materialName='+materialName+'&supplierName='+supplierName+'&customerName='+customerName+
                '&suttleDate='+suttleDate+'&suttleDateTo='+suttleDateTo;
    });
</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#measure_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
                var measureId = $("#measureId").val();
                var moveTypes = $("#outin").val();
                var unload = $("#unload").val();
                var returnSymbol = $("#return").val();
                var closeSymbol = $("#close").val();
                var carId = $("#carId").val();

                var materialName = $('#materialNameSearch').val();
                var supplierName = $('#supplierNameSearch').val();
                var customerName = $('#customerNameSearch').val();

                var suttleDate = $('#suttleDateSearch').val();
                var suttleDateTo = $('#suttleDateToSearch').val();

				var handler = '/measure-list/'+pageNumber+"/"+pageSize+'?measureId='+measureId
                        +'&materialName='+materialName+'&supplierName='+supplierName+'&customerName='+customerName
                        +'&suttleDate='+suttleDate+'&suttleDateTo='+suttleDateTo
                        +'&moveTypes='+moveTypes+'&unloadSymbol='+unload+'&returnSymbol='+returnSymbol+'&closeSymbol='+closeSymbol+'&carId='+carId;
				$('#measure_table').datagrid('options').url = handler;
				$('#measure_table').datagrid('reload');
			}
		});
	})
</script>